package com.hnx.admin.aurora.utils;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONWriter;

import java.nio.charset.StandardCharsets;

/*
创建人： 倔强的头发
创建时间：2025/5/16
功能描述:

*/
public class JsonUtils {
    public static <T> String serialize(T object) {
        return JSON.toJSONString(object, JSONWriter.Feature.WriteNulls);
    }

    public static <T> T deserialize(String json, Class<T> clazz) {
        return JSON.parseObject(json, clazz);
    }

    public static byte[] serializeToBytes(Object object) {
        return serialize(object).getBytes(StandardCharsets.UTF_8);
    }

    public static <T> T deserializeFromBytes(byte[] bytes, Class<T> clazz) {
        return deserialize(new String(bytes, StandardCharsets.UTF_8), clazz);
    }
}
